package cn.stylefeng.guns.modular.tool.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.tool.entity.ToolExpressReconciliationYmInstall;
import cn.stylefeng.guns.modular.tool.mapper.ToolExpressReconciliationYmInstallMapper;
import cn.stylefeng.guns.modular.tool.model.params.ToolExpressReconciliationYmInstallParam;
import cn.stylefeng.guns.modular.tool.model.result.ToolExpressReconciliationYmInstallResult;
import  cn.stylefeng.guns.modular.tool.service.ToolExpressReconciliationYmInstallService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 医美物料报价设置 服务实现类
 * </p>
 *
 * @author zhucx
 * @since 2023-07-22
 */
@Service
public class ToolExpressReconciliationYmInstallServiceImpl extends ServiceImpl<ToolExpressReconciliationYmInstallMapper, ToolExpressReconciliationYmInstall> implements ToolExpressReconciliationYmInstallService {

    @Override
    public void add(ToolExpressReconciliationYmInstallParam param){
        ToolExpressReconciliationYmInstall entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(ToolExpressReconciliationYmInstallParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(ToolExpressReconciliationYmInstallParam param){
        ToolExpressReconciliationYmInstall oldEntity = getOldEntity(param);
        ToolExpressReconciliationYmInstall newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public ToolExpressReconciliationYmInstallResult findBySpec(ToolExpressReconciliationYmInstallParam param){
        return null;
    }

    @Override
    public List<ToolExpressReconciliationYmInstallResult> findListBySpec(ToolExpressReconciliationYmInstallParam param,Long operateId){
        return this.baseMapper.findListBySpec(param,operateId);
    }

    @Override
    public LayuiPageInfo findPageBySpec(ToolExpressReconciliationYmInstallParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(ToolExpressReconciliationYmInstallParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private ToolExpressReconciliationYmInstall getOldEntity(ToolExpressReconciliationYmInstallParam param) {
        return this.getById(getKey(param));
    }

    private ToolExpressReconciliationYmInstall getEntity(ToolExpressReconciliationYmInstallParam param) {
        ToolExpressReconciliationYmInstall entity = new ToolExpressReconciliationYmInstall();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
